/* 1.字符串的常用操作 */
function strOper() {
    let mystr = "hello.jpg";
    /* 判头 */
    let isStart = mystr.startsWith("h");    // true
    /* 判尾 */
    let isJPG = mystr.endsWith("jpg");      // true
    /* 是否包含 */
    let isContent = mystr.includes("e");    // true
    /* 寻找全部(也可以不用正则) */
    let textList = "catooocut".match(new RegExp("c[auo]t", "g"));
    /* 替代全部(也可以不用正则) */
    let newText = "catooocut".replace(new RegExp("c[auo]t", "g"));
    /* 重复,等价py的"UFO"**3 */
    let repeatStr = "UFO".repeat(3);        // UFOUFOUFO
}

/* 2.格式化字符串 */
function format() {
    let name = "Xiaoming";
    let age = 12;
    let text = `I am ${name}, ${age} years old`;
    console.log(text);
}

/* 3.自带转义,相当于自动帮你加了个反斜杠 */
function raw() {
    let str = "Hi\t${1+2}";
    let rawStr = String.raw`Hi\t${1+2}`;
    console.log(str);    // Hi	${1+2}
    console.log(rawStr); // Hi\t3
}

/* 4.遍历每一个字符 */
function traverseStr() {
    let mystr = "Hello";
    for (let code of mystr) {
        console.log(code);
    }
}

/* 5.记住!Unicode是字符集, 不是一种编码格式 */
function unicodeStr() {
    let mystr = "\u{70c1}"; // unicode字符集里面的70c1就是烁
    console.log(mystr);
}

/* 6.Buffer不支持GBK */
function str2Bytes() {
    let mystr = "烁";
    let buf = new Buffer(mystr, 'utf-8');
    console.log(buf);
}

/* 7.不知道实用价值在哪里的... */
function funcFormat() {
    let user = {name: "Xiaoming", age:12};
    function show(str, arg1, arg2) {
        console.log(str);
        console.log(arg1);
        console.log(arg2);
        return str;
    }
    console.log(show`I am ${user.name},${user.age} years old`)
}

